findAll

用途

查找所有满足特定条件的domain类对象。

举例

// 查询所有
Book.findAll()
//使用占位符参数
Book.findAll("from Book as b where b.author=?",['Dan Brown'])
//从第5条开始查出10条记录,按出版日期排序 

Book.findAll("from Book as b where b.author=? order by b.releaseDate",
['Dan Brown'],[max:10,offset:5])

//max/offset用法示例 def query = "from Book as b where b.author='Dan Brown' order by b.releaseDate" //查出头10条 Book.findAll(query,[max:10]) // 从第5条记录起,查出10条 Book.findAll(query,[max:10,offset:5])

// 使用命名参数的例子 (since 0.5) Book.findAll("from Book as b where b.author=:author", [author:'Dan Brown']) Book.findAll("from Book as b where b.author=:author", [author:'Dan Brown'], [max:10, offset:5]) Book.findAll("from Book as b where b.author in (:authors)", [authors:['Dan Brown','Jack London']])

//多表联合查询 Book.findAll("from Book as b where not exists (from Borrow as br where br.book = b)")

// 样本查询 def b = new Book(author:"Dan Brown") Book.findAll(b)

描述

findAll方法允许使用HQL查询,按样本查询结果为匹配实例集合。分页可以通过追加max 和 offset 参数控制:

Book.findAll("from Book as b where b.author=:author", 
 		[author:'Dan Brown'], [max:10, offset:5])

该方法的基本语法:

Book.findAll()
Book.findAll( String query )
Book.findAll( String query, Collection positionalParams )
Book.findAll( String query, Collection positionalParams, Map paginateParams )
Book.findAll( String query, Map namedParams )
Book.findAll( String query, Map namedParams, Map paginateParams )
Book.findAll( Book example )

参数: